package com.kejso.service;

import com.kejso.dao.db.ScholarRepository;
import com.kejso.dao.solr.SolrScholarRepository;
import com.kejso.model.db.Scholar;
import com.kejso.model.solr.SolrScholar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by DELL on 2018/4/23.
 */
@Service
public class ScholarService {

    @Autowired
    SolrScholarRepository solrScholarRepository;

    @Autowired
    ScholarRepository scholarRepository;

    public List<SolrScholar> findByName(String name){
        Sort sort = new Sort(Sort.Direction.DESC, "base_score_d");
        return solrScholarRepository.findByName(name,sort);
    }

    public SolrScholar findById(String id){
        return solrScholarRepository.findById(id);
    }

    public List<SolrScholar> findByNameAndOrg(String name,String org){
        return solrScholarRepository.findByNameAndOrg(name,org);
    }

    public void updateScholarSolr(SolrScholar solrScholar){
        solrScholarRepository.save(solrScholar);
    }

    @Transactional
    public void updateScholarDB(Scholar scholar){
        scholarRepository.save(scholar);
    }

    public void delete(String id) {
        solrScholarRepository.delete(id);
        scholarRepository.delete(id);
    }


}
